import FeedbackDtlApi from '../../../../public/js/common/api/ctn/hddetails.api.js';
import doT from '../../../vendor/template/doT.js';
import { requestFilePath } from '../../../../public/js/common/api/file-request.js';

(function (window, document, $) {
    'use strict';
    $('body').attr('data-weui-theme', 'light'); // 强制光明模式
    let _template = doT.template($('#hddetails-template').text());
    let _vm;
    $(function () {
        _vm = new Vue({
            el: '#hddetails',
            mounted() {
                if (getUrlKey('category') == 2) {
                    document.title = '数据泄露 - 详情';
                } else if (getUrlKey('category') == 1) {
                    document.title = '隐患上报 - 详情';
                }
            },
        });
        _initCommand();
    });
    // 命令初始化
    const _initCommand = () => {
        FeedbackDtlApi.getDangerDetails(getUrlKey('id')).then((res) => {
            // $('#hd-details').empty().append(_template(res));
            let detailsdata = res;
            let imageArr = [];

            if (Utils.IsNotNull(res.attachments)) {
                res.attachments.forEach((item) => {
                    FeedbackDtlApi.requestFilePath(item.id).then((res) => {
                        imageArr.push({ url: res, id: item.id });
                        let alldata = { ...{ imageArr: imageArr }, ...detailsdata };
                        $('#hd-details').empty().append(_template(alldata));

                        if (detailsdata.category == 2) {
                            $('.datalose').css('display', 'none');
                            $('#deptitle').text('涉及事业部');
                            $('#typetitle').text('数据类别');
                            $('#sugtitle').text('涉及内容描述');
                        } else {
                            $('.datalose').css('display', 'block');
                            $('#deptitle').text('所属事业部');
                            $('#typetitle').text('隐患类型');
                            $('#sugtitle').text('整改建议');
                        }
                    });
                });
            } else {
                $('#hd-details').empty().append(_template(res));
                if (detailsdata.category == 2) {
                    $('.datalose').css('display', 'none');
                    $('#deptitle').text('涉及事业部');
                    $('#typetitle').text('数据类别');
                    $('#sugtitle').text('涉及内容描述');
                } else {
                    $('.datalose').css('display', 'block');
                    $('#deptitle').text('所属事业部');
                    $('#typetitle').text('隐患类型');
                    $('#sugtitle').text('整改建议');
                }
            }
        });
        $(document).on('click', '.picture_query img', function () {
            const id = $(this).attr('img-Id');
            requestFilePath(id).then((res) => {
                $.photoBrowser({
                    items: [res.data],
                }).open();
                // style = "min-height:100vh;"
            });
        });
        new Swiper('.swiper-container', {
            direction: 'horizontal', // 水平切换选项
            autoplay: true,
            // 如果需要分页器
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
            observer: true,
            observeParents: true,
        });
    };
    /** 获取地址栏的 参数  传入 字段返回值 */
    const getUrlKey = (name) => {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    };
})(window, document, jQuery);
